﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MS.InformationManagement.DAL.DocumentCenter;
using MS.InformationManagement.Support.Constants;

namespace MS.InformationManagement.BLL.ReceivedDocuments
{
    public static class Support
    {

        public static IEnumerable<DocumentoImpreso> GetPrintedEntities(DCDocumentCenterDataContext dataContext,IList<int> selectedItems)
        {
            foreach (var docId in selectedItems)
            {
                var selectedPrintedDocument = (from doc in dataContext.DocumentosImpresos
                                               where doc.Id == docId
                                               select new DocumentoImpreso()
                                               {
                                                   AreaDelDocumento = doc.AreaDelDocumento,
                                                   Asunto = doc.Asunto,
                                                   BibliotecaDelDocumento = doc.BibliotecaDelDocumento,
                                                   IdDocumento = doc.IdDocumento,
                                                   NoRadicado = doc.NoRadicado,
                                                   RemitenteDestinatario = doc.RemitenteDestinatario,
                                                   TipoDocumento = doc.TipoDocumento,
                                                   Title = doc.Title,
                                                   Pais = doc.Pais
                                               }).FirstOrDefault();
                if (selectedPrintedDocument == null)
                    throw new Exception(string.Format(ExceptionConstants.ERROR_ITEM_NO_ENCONTRADO, docId));

                selectedPrintedDocument.Id = null;
                yield return selectedPrintedDocument;
            }
        }

        public static IEnumerable<DocumentoImpreso> GetPrintedAttachedEntities(DCDocumentCenterDataContext dataContext, IList<int> selectedItems)
        {
            foreach (var docId in selectedItems)
            {
                var selectedPrintedDocument = (from doc in dataContext.DocumentosImpresos
                                               where doc.Id == docId
                                               select doc).FirstOrDefault();
                if (selectedPrintedDocument == null)
                    throw new Exception(string.Format(ExceptionConstants.ERROR_ITEM_NO_ENCONTRADO, docId));

                yield return selectedPrintedDocument;
            }
        }


    }

}
